package com.itheima.controller.pms;


import com.itheima.core.PageInfo;
import com.itheima.core.R;
import com.itheima.pojo.pms.PmsBrand;
import com.itheima.pojo.pms.vo.UpdateFactoryStatusVo;
import com.itheima.pojo.pms.vo.UpdateShowStatusVo;
import com.itheima.service.pms.PmsBrandService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import java.util.List;
@Slf4j
@RestController
@RequestMapping("/brand")
public class PmsBrandController {

    @DubboReference
    private PmsBrandService pmsBrandService;


    /**
     * 添加品牌
     * @param pmsBrand
     * @return
     */
    @PostMapping("/create")
    public R CreateProduct(@RequestBody PmsBrand pmsBrand){
        pmsBrandService.save(pmsBrand);
        return R.success("","");
    }

    /**
     * 批量删除品牌
     * @param ids
     * @return
     */
    @PostMapping("/delete/batch")
    public R delete(@RequestBody List<Long> ids){
        pmsBrandService.removeByIds(ids);
        return R.success("","");
    }

    /**
     * 删除品牌
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public R deleteId(@PathVariable("id")  Long id){
        pmsBrandService.removeById(id);
        return R.success("","");
    }

    /**
     * 根据品牌名称分页获取品牌列表
     * @return
     */
    @GetMapping("list")
    public R List(String keyword,@RequestParam(defaultValue ="1")Integer pageNum,@RequestParam(defaultValue ="5")Integer pageSize){
        PageInfo brandList = pmsBrandService.listBrand(keyword, pageNum, pageSize);
        return R.success("success",brandList);
    }

    /**
     * 获取全部品牌列表
     * @return
     */
    @GetMapping("listAll")
    public R listAll(){
       List<PmsBrand> list = pmsBrandService.list();
        return R.success(list);
    }

    /**
     * 批量更新厂家制造商状态
     * @param updateFactoryStatusVo
     * @return
     */
    @PostMapping("update/factoryStatus")
    public R  UpdateFactoryStatus( UpdateFactoryStatusVo updateFactoryStatusVo){
        pmsBrandService.updateFactoryStatus(updateFactoryStatusVo.getIds(),updateFactoryStatusVo.getFactoryStatus());
        return R.success();
    }

    /**
     * 批量更新显示状态
     * @param updateShowStatusVo
     * @return
     */
    @PostMapping("update/showStatus")
    public R updateShowStatus(  UpdateShowStatusVo updateShowStatusVo) {
        pmsBrandService.updateShowStatus(updateShowStatusVo.getIds(),updateShowStatusVo.getShowStatus());
    return R.success();
    }

    /**
     * 更新品牌
     * @param id
     * @param pmsBrand
     * @return
     */
    @PostMapping("update/{id}")
    public R update(@PathVariable("id") Long id,
                     @RequestBody PmsBrand pmsBrand) {
        pmsBrand.setId(id);
        pmsBrandService.updateById(pmsBrand);
        return R.success();
    }

    /**
     * 根据编号查询品牌信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R getId(@PathVariable  Long id) {
        PmsBrand pmsBrand=pmsBrandService.getById(id);
    return R.success(pmsBrand);
    }

}
